package ttc.sftp.data;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;

public class SFile {
	private String path;
	private String name;
	private Boolean isDirectory;
	private ChannelSftp channel;

	public String getPath() {
		return path;
	}

	public String getName() {
		return name;
	}

	public Boolean isDirectory() {
		return isDirectory;
	}

	public SFile(String Path, ChannelSftp channel) {
		this.channel = channel;
		try {
			channel.cd(Path);
			this.path = channel.pwd();
			this.isDirectory = this.channel.stat(Path).isDir();
			// /kimcuong/duy

			int temp = 0;
			for (int i = this.path.length() - 1; i >= 0; i--) {
				if (String.valueOf(this.path.charAt(i) - 1).compareTo("/") == 0) {
					temp = i;
					break;
				}
			}
			this.name = this.path.substring(temp + 1);
		} catch (SftpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Vector<SFile> getVectorFile() throws SftpException {

		Vector<SFile> vectorFiles = new Vector<SFile>();
		channel.cd(path);
		vectorFiles = channel.ls(path);
		return vectorFiles;

	}

	public String GetParent() {

		int temp = 0;
		for (int i = this.path.length(); i >= 0; i--) {
			if (String.valueOf(this.path.charAt(i - 1)).compareTo("/") == 0) {
				temp = i;
				break;
			}
		}
		String temp1 = this.path.substring(0, temp);
		return temp1;

	}

	public String getCurrentPath(){
		String temp = null;
		try {
			temp = channel.pwd();
		} catch (SftpException e) {
		}
		return temp;
	}

}
